package com.alex.statistics.pojo.request.spatialAnalysis;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

@Data
@Schema(
        description = "核密度估计()请求参数",
        example = """
        {
          "points": [
            {"x": 1.2, "y": 2.5, "weight": 1.0},
            {"x": 3.4, "y": 5.6, "weight": 0.8},
            {"x": 7.8, "y": 9.0, "weight": 1.2}
          ],
          "bandwidth": 1.5,
          "gridSize": 50,
          "includeRawMatrix": true
        }"""
)
public class KernelDensityRequest {

    @Data
    @Schema(description = "空间点坐标及权重")
    public static class Point {
        @Schema(
                description = "X坐标（经度或投影坐标）",
                requiredMode = Schema.RequiredMode.REQUIRED,
                example = "116.404"
        )
        @NotNull(message = "X坐标不能为空")
        private Double x;

        @Schema(
                description = "Y坐标（纬度或投影坐标）",
                requiredMode = Schema.RequiredMode.REQUIRED,
                example = "39.915"
        )
        @NotNull(message = "Y坐标不能为空")
        private Double y;

        @Schema(
                description = "点权重值（默认等权重）",
                defaultValue = "1.0",
                example = "1.0",
                minimum = "0",
                exclusiveMinimum = true
        )
        @Min(value = 0, message = "权重必须大于0")
        private double weight = 1.0;
    }

    @Schema(
            description = "空间点数据集（至少需要2个点）",
            requiredMode = Schema.RequiredMode.REQUIRED,
            example = """
            [
              {"x": 116.404, "y": 39.915},
              {"x": 116.408, "y": 39.918}
            ]"""
    )
    @Size(min = 2, message = "至少需要2个空间点")
    @NotNull(message = "点集不能为null")
    @Valid  // 级联校验Point对象内部约束
    private List<Point> points;

    @Schema(
            description = "带宽参数（控制平滑程度）",
            defaultValue = "1.0",
            example = "1.5",
            minimum = "0.01",
            maximum = "100"
    )
    @Min(value = 0, message = "带宽必须大于0")
    private double bandwidth = 1.0;

    @Schema(
            description = "输出网格尺寸（N×N像素）",
            defaultValue = "100",
            example = "50",
            minimum = "10",
            maximum = "1000"
    )
    @Min(value = 10, message = "网格尺寸最小为10")
    private int gridSize = 100;

    @Schema(
            description = "是否返回原始密度矩阵",
            defaultValue = "false",
            example = "true"
    )
    private boolean includeRawMatrix = false;

    @Schema(
            description = "CURL调用示例",
            example = """
            curl -X POST "http://api.example.com/spatial/kde" \\
                 -H "Content-Type: application/json" \\
                 -d '{
                   "points": [
                     {"x": 116.404, "y": 39.915},
                     {"x": 116.408, "y": 39.918}
                   ],
                   "bandwidth": 1.5,
                   "gridSize": 50
                 }'""",
            hidden = false
    )
    private transient String curlExample;
}